<?php
// 重置密码页
header("content-type:text/html;charset=utf-8");
$ID = $_POST['userID'];
$pwd = $_POST['userPassword'];
$phone = $_POST['phone'];
include_once("conn.php");
include_once("u_getLoginInfo.php");
if($status != 1){
    die("<script>alert('账户处于待注销状态，不可操作！');history.go(-1);</script>");
}

$select = "SELECT * FROM user_infos WHERE user_ID = '" . $ID . "'";
if ($result_select = mysqli_query($connect_DB, $select)) {
    if (mysqli_num_rows($result_select) == 0) {
        echo "<script>alert('未查询到 " . $ID . " 用户信息！请检查！');history.go(-1);</script>";
        exit();
    } else {
        if(mysqli_fetch_object($result_select)->user_Phone != $phone){
            echo "<script>alert('您输入的预留手机号信息有误！请检查！');history.go(-1);</script>";
            exit();
        }else{
            $update = "UPDATE user_infos SET user_Password = '" . $pwd . "' WHERE user_ID = '" . $ID . "'";
            if (mysqli_query($connect_DB, $update)) {
                echo "<script>alert('重置密码成功！请返回登录！');location='user_login.html';</script>";
            } else {
                echo "<script>alert('重置密码失败！请稍后重试！');history.go(-1);</script>";
                exit();
            }
        }
        
    }
} else {
    echo "<script>alert('重置密码失败！请稍后重试！');history.go(-1);</script>";
    exit();
}

$connect_DB->close();

?>